package com.jnu.hc.jnuhcusercms.service;

import com.jnu.hc.jnuhcusercms.domain.Users;
import com.jnu.hc.jnuhcusercms.dto.ResponseObject;
import com.jnu.hc.jnuhcusercms.exception.HcAPPException;
import com.jnu.hc.jnuhcusercms.exception.HcAPPExceptionEnum;
import com.jnu.hc.jnuhcusercms.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    UsersMapper usersMapper;
    //处理登录请求
    @Override
    public ResponseObject<Users> login(Users user){
        ResponseObject<Users> responseObject=null;
        Users result=usersMapper.selectByPrimaryKey(user.getUserId());
        if(result==null){
            //发送信息
            //return
            throw new HcAPPException(HcAPPExceptionEnum.MOBILE_NOT_REGISTERED.getCode(), HcAPPExceptionEnum.MOBILE_NOT_REGISTERED.getMessage());
        }
        if(!result.getPassword().equals(user.getPassword())){
            //发送信息
            //return
            result.setPassword("");
            throw new HcAPPException(HcAPPExceptionEnum.PASSWORD_IS_WRONG.getCode(),  HcAPPExceptionEnum.PASSWORD_IS_WRONG.getMessage());
        }
        result.setPassword("");
        responseObject=new ResponseObject<>(ResponseObject.SUCCESS_STATUS,ResponseObject.SUCCESS_DESC,result);
        return responseObject;
    }
}
